package neusoft.yuejian_11.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.squareup.picasso.Picasso;

import java.util.List;

import neusoft.yuejian_11.activity.MasterDetailActivity;
import neusoft.yuejian_11.base.BaseListAdapter;
import neusoft.yuejian_11.bean.MasterBean;
import neusoft.yuejian_11.R;
import neusoft.yuejian_11.viewHolder.MasteritemViewHolder;

import static neusoft.yuejian_11.interF.Const.BASE_URI;

/**
 * Created by neusoft on 2017/10/9.
 */

public class MasterListAdapter extends BaseListAdapter {
    public MasterListAdapter(Context context, List data) {
        super(context, data);
    }

    @Override
    protected RecyclerView.ViewHolder onCreateVH(ViewGroup parent, LayoutInflater layoutInflater, int viewType) {
        View itemView = layoutInflater.inflate(R.layout.item_master_list, parent, false);
        MasteritemViewHolder viewHolder = new MasteritemViewHolder(itemView);
        return viewHolder;
    }

    @Override
    protected void onBindVH(RecyclerView.ViewHolder holder, List data, int position) {
        MasterBean master = (MasterBean) data.get(position);
        MasteritemViewHolder viewHolder = (MasteritemViewHolder) holder;

        final String masterName = master.getPm_name();
        String masterInfo = master.getPm_info();
        final int masterId = master.getPm_id();

        viewHolder.masterNameView.setText(masterName);
        viewHolder.masterInfoView.setText(masterInfo);

        //String realPath = “file://”+new File(event.photo).getPath();
        final String masterPic = BASE_URI+"professorpic/"+master.getPm_pic();
        //String Url = "http://10.0.2.2/yuejian14/Public/Admin/clubphoto/87.jpg";
        Picasso.with(context)
                .load(masterPic)
                .placeholder(R.drawable.ic_club)
                .error(R.drawable.ic_noclub)
                .into(viewHolder.imageView);

        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //启动新的Activity--俱乐部详情
                Intent intent = new Intent(context, MasterDetailActivity.class);
                intent.putExtra("pm_name",masterName);
                intent.putExtra("pm_id",masterId);
                intent.putExtra("pm_pic",masterPic);
                context.startActivity(intent);
            }
        });


    }
}
